package com.zg.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.mqtt.MqttDecoder;
import io.netty.handler.codec.mqtt.MqttEncoder;
import io.netty.handler.timeout.IdleStateHandler;

public class ChildChannelHandler extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();

        /**
         * 这里是管理处理流程
         */
        pipeline.addLast(new IdleStateHandler(600,600,1200));//加入心跳
        pipeline.addLast("encoder", MqttEncoder.INSTANCE);
        pipeline.addLast("decoder",new MqttDecoder());
        pipeline.addLast(new MqttMsgInboundHandler());//加入mqtt消息处理模块，自己定义的
    }
}
